package defectsim.resources.deformation;

import javax.vecmath.Vector2d;

import repast.simphony.parameter.Parameters;

import defectsim.SimulationEnvironment;

public class CyclicStress implements Deformation{

	private SimulationEnvironment environment = SimulationEnvironment.getInstance();
	
	private int cyclicTickCount;
	private double maxExternalStress;
	
	public CyclicStress(int cyclicTickCount, double externalStress){
		this.cyclicTickCount = cyclicTickCount;
		this.maxExternalStress = externalStress;
	}
	
	@Override
	public Vector2d updateExternalStress() {
		double frequency = environment.getCurrentTick() / cyclicTickCount;
		double angularFrequency = 2.0 * Math.PI * frequency;
		return new Vector2d(maxExternalStress * Math.sin(angularFrequency), 0.0);
	}

	@Override
	public double getCycle() {
		return cyclicTickCount / environment.getCurrentTick();
	}
}
